Skip to content

Fix a few simple sendability issues#832

Merged
glbrntt merged 2 commits intoswift-server:mainfrom
glbrntt:strict-low-hanging-fruit
Apr 28, 2025
Merged

Fix a few simple sendability issues#832
glbrntt merged 2 commits intoswift-server:mainfrom
glbrntt:strict-low-hanging-fruit

Conversation

@glbrntt
Copy link
Copy Markdown
Collaborator

@glbrntt glbrntt commented Apr 28, 2025

Motivation:

We're about to go on a sendability journey. Let's pick some low hanging fruit to get started.

Modifications:

  • Add a few assume-isolated calls
  • Stop using static var
  • Use a dispatch group instead of a work item to wait for work to be done.

Result:

Fewer warnings

Motivation:

We're about to go on a sendability journey. Let's pick some low hanging
fruit to get started.

Modifications:

- Add a few assume-isolated calls
- Stop using static var
- Use a dispatch group instead of a work item to wait for work to be
  done.

Result:

Fewer warnings
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Apr 28, 2025
@glbrntt glbrntt enabled auto-merge (squash) April 28, 2025 09:47
@glbrntt glbrntt closed this Apr 28, 2025
auto-merge was automatically disabled April 28, 2025 09:56

Pull request was closed

@glbrntt glbrntt reopened this Apr 28, 2025
@glbrntt glbrntt enabled auto-merge (squash) April 28, 2025 10:31
let errorStorage: NIOLockedValueBox<Error?> = NIOLockedValueBox(nil)
let continuation = DispatchWorkItem {}
let dispatchGroup = DispatchGroup()
dispatchGroup.enter()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this should probably use the condition variable workaround we used in NIO to avoid triggering the main thread checker.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, good idea

self.connection = connection
}

static let none = Action(request: .none, connection: .none)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially silly question but was this unsafe?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not "unsafe" per-se as neither .none case contains anything. However, Action isn't Sendable (and shouldn't be) so the compiler appropriately produces a warning here.

@glbrntt glbrntt requested a review from Lukasa April 28, 2025 12:56
@glbrntt glbrntt merged commit 0e715a2 into swift-server:main Apr 28, 2025
23 of 24 checks passed
@glbrntt glbrntt deleted the strict-low-hanging-fruit branch April 28, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants